package com.test4;

/****
 * 输入线程资源
 *
 */
public class IntThrad extends Thread {
	private Res res;

	public IntThrad(Res res) {
		this.res = res;
	}

	@Override
	public void run() {
		int count = 0;
		while (true) {
			try {
				res.lock.lock();
				if (res.flag) {
					try {
						// 当前线程变为等待，但是可以释放锁
						res.condition.await();
					} catch (Exception e) {

					}
				}
				if (count == 0) {
					res.userName = "小军";
					res.userSex = "男";
				} else {
					res.userName = "小红";
					res.userSex = "女";
				}
				count = (count + 1) % 2;
				res.flag = true;
				res.condition.signal();
			} catch (Exception e) {
			} finally {
				res.lock.lock();
			}

		}
	}
}
